<template>
    <div class="changemoneyItem">
        <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="报销人" prop="name">
        <el-input v-model="ruleForm.name"></el-input>
      </el-form-item>
      <el-form-item label="报销类型" prop="type">
        <el-radio-group v-model="ruleForm.type">
          <el-radio label="餐费"></el-radio>
          <el-radio label="打车费"></el-radio>
          <el-radio label="其他费用"></el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="报销时间" required>
        <el-col :span="22">
          <el-form-item prop="date">
            <el-date-picker v-model="ruleForm.date" value-format="yyyy-MM-dd"
              style="width: 100%" type="string" placeholder="选择日期">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-form-item>
      <el-form-item label="报销金额" prop="money">
        <el-input v-model="ruleForm.money"></el-input>
      </el-form-item>
      <el-form-item label="报销说明" prop="introduce">
        <el-input type="textarea" v-model="ruleForm.introduce"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')"
          >修改信息</el-button
        >
        <el-button @click="$router.go(-1)">返回</el-button>
      </el-form-item>
    </el-form>
    </div>
</template>

<script>
    export default {
        data() {
          return {
            ruleForm: {
                num:'',
                name: "",
                money: 0,
                date: "",
                type: "",
                introduce: "",
                status:''
            },
            rules: {
                name: [
                { required: true, message: "请输入报销人名称", trigger: "blur" },
                { min: 2, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" },
                ],
                date: [
                {
                    type: "string",
                    required: true,
                    message: "请选择报销日期",
                    trigger: "change",
                },
                ],
                type: [
                { required: true, message: "请选择报销类型", trigger: "change" },
                ],
                introduce: [{ required: false, message: "请填写报销说明", trigger: "blur" }],
                money: [{ required: true, message: "请填写报销金额", trigger: "blur" }],
            },
            };
        },
        mounted() {
            let data = this.$store.state.money.moneyList.userData

            if(data){
                const res = data.find(item => item.num === this.$route.query.num - 0)
                this.ruleForm = res
            }
        },
        methods: {
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                         this.$message.success('修改成功！')
                        this.$router.replace('/admin/money')
                    }
                });
            },
        },
    }
</script>

<style lang="scss" scoped>
.changemoneyItem {
    width: 400px;
    min-height: 500px;
    margin-top: 50px;
    margin-left: 50px;
}
.ivu-btn-ghost {
    color: pink;
}
</style>